/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entities.InforContact;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author MrChinh
 */
public class ListInforContact {
    ConnectDB myConn = new ConnectDB();
    Connection conn;
    
    public List<InforContact> getListInforContact(){
        List<InforContact> listIC = new  ArrayList<InforContact>();
        try {
            conn = myConn.getConnect();
            Statement stmt  = conn.createStatement();
            String sql = "SELECT * FROM InforContact";
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                InforContact ifc = new InforContact();
                ifc.setInforID(rs.getInt(1));
                ifc.setContactName(rs.getString(2));
                ifc.setContactAddress(rs.getString(3));
                ifc.setContactEmail(rs.getString(4));
                ifc.setContactphone(rs.getString(5));
                listIC.add(ifc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listIC;
    }
    
    public InforContact getContactByVacancyId(String vId){
        InforContact ct = new InforContact();
        StringBuilder sqlBuilder = new StringBuilder();
        sqlBuilder.append("SELECT CT.* ");
        sqlBuilder.append("FROM ");
        sqlBuilder.append("InforContact CT ");
        sqlBuilder.append("INNER JOIN Vacancy V on CT.InforID = V.InforID ");
        sqlBuilder.append("WHERE V.VacancyID = '");
        sqlBuilder.append(vId);
        sqlBuilder.append("'");
        String sql = sqlBuilder.toString();
        try {
            conn = myConn.getConnect();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            while(rs.next()){
                ct.setInforID(rs.getInt("InforID"));
                ct.setContactName(rs.getString("ContactName"));
                ct.setContactAddress(rs.getString("ContactAddress"));
                ct.setContactEmail(rs.getString("ContactEmail"));
                ct.setContactphone(rs.getString("Contactphone"));
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return ct;
    }
}
